import sys
from PyQt5.QtWidgets import *
from PyQt5.QtGui import *
from PyQt5.QtCore import *


class RadioButtonGroup(QWidget):
    clicked = pyqtSignal()

    def __init__(self, button_list):
        super(RadioButtonGroup, self).__init__()
        if len(button_list) == 0:
            raise Exception("button list is none")
        self.__button_list = button_list
        self.__currentText = self.__button_list[0]
        self.initUI()

    def initUI(self):
        # 水平布局
        self.hbox = QHBoxLayout()
        self.beClickedList = []

        for item in range(len(self.__button_list)):
            self.beClickedList.append(item)
            self.beClickedList[item] = QRadioButton(self)
            self.hbox.addWidget(self.beClickedList[item])
            self.beClickedList[item].setText(self.__button_list[item])
            self.beClickedList[item].clicked.connect(lambda: self.btnBeClicked(self.sender().text()))
        self.beClickedList[0].setChecked(True)

        self.setLayout(self.hbox)

    def btnBeClicked(self, btnText):
        self.__currentText = btnText
        print(self.__currentText)
        return self.__currentText


if __name__ == '__main__':
    button_list = ['faker', 'miya', 'hello', 'dopa']
    app = QApplication(sys.argv)
    RadioButtonGroup = RadioButtonGroup(button_list)
    RadioButtonGroup.show()
    sys.exit(app.exec_())
